package goodroommate.ui.info;

import java.io.IOException;
import java.util.LinkedList;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import goodroommate.domain.News;
import goodroommate.exception.DatabaseException;
import goodroommate.service.INewsService;
import goodroommate.service.impl.NewsService;

/**
 * Servlet implementation class SearchInfoServlet
 */
@WebServlet("/Info/SearchInfo")
public class SearchInfoServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	INewsService newsService=new NewsService();
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public SearchInfoServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		LinkedList<News>news=null;
		try{
			news=newsService.getAllNews();
		}catch(DatabaseException e){
			response.sendError(500);
			return;
		}
		request.setAttribute("news", news);
		request.getRequestDispatcher("searchinfo.jsp").forward(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
